<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SplitContainer Demo</title>
     <style type="text/css">
            @import "../dojo/dojo-release-1.0.0/dijit/themes/tundra/tundra.css";
            @import "../dojo/dojo-release-1.0.0/dojo/resources/dojo.css";
            @import "../dojo/dojo-release-1.0.0/dojox/grid/_grid/tundraGrid.css";
            @import "../dojo/dojo-release-1.0.0/dojox/grid/_grid/Grid.css";
   
   // div.split1{height:1280px; width:930px}
			
			
        </style>
        <script type="text/javascript" src="../dojo/dojo-release-1.0.0/dojo/dojo.js"
                djConfig="parseOnLoad: true, isDebug: true,locale: 'zh-cn', extraLocale: ['zh-TW', 'fr']"></script>
 <script>
    
            dojo.require("dojo.data.ItemFileWriteStore");
            dojo.require("dijit.layout.SplitContainer");
            dojo.require("dijit.layout.ContentPane");
            dojo.require("dijit.Tree");
            dojo.require("dojo.parser");
            dojo.require("dijit._tree.dndSource");
            dojo.require("dijit.layout.TabContainer");
            dojo.require("dijit.form.Button");
            dojo.require("dojox.grid.Grid");
            dojo.require("dojox.grid._data.model");
            dojo.require("dojo.i18n");
            </script>
        
<script type="text/javascript" src="../js/soapclient.js">
        </script>
<script type="text/javascript" >


         var data =new Array();
         var areadata =new Array();
         var placedata = [[false,"","","",""]];
         var provincedata = new Array();
         var citydata = new Array();
         var cityareadata = new Array();
         var poptarts ={ label:'name',identifier:'eId',items:data};
         var popStore = new dojo.data.ItemFileWriteStore({data: poptarts});
          //按钮  
          var deletedata =new Array();
          var adddata =new Array();
          var updata =new Array();
          
          
          
           model = new dojox.grid.data.Table(null, placedata);
          var layout =[{type: 'dojox.GridRowView', width: '20px' },{
                       
                        rows: [
                                [
                                 { name: 'Mark', width: 2, styles: 'text-align: center;', editor: dojox.grid.editors.Bool },
                                 { name: 'no', width: 2, get: function(inRowIndex){ return inRowIndex+1;} },
                                 {name: 'placeName', width: 20,editor: dojox.grid.editors.Input },
                                 {name: 'postCode', width: 20, editor: dojox.grid.editors.Input},
                                 {name: 'remark', width: 20, editor: dojox.grid.editors.Input}
                                ]
                              ]
                        }];
                        
                          
       	
	
          //保存列表
       
            
          addRow = function(){
	         	gridWidget.addRow([false,"","","",""]);
	         	//adddata.splice(adddata.length,thisCell);
	         } 
	         
          function call_funUpd() {
           var s = gridWidget.selection.getSelected();
           
           for(var i=0;i<s.length;i++){
           var thisCell=gridWidget.model.data[i];
             var padd = new SOAPClientParameters2();
             var url = "http://localhost:8080/logistics-ws/services/BasicManageService";
             var placevo=new Object();
            
             placevo.id=999;
             placevo.placeName=thisCell[1];
             alert(thisCell[2]);
             placevo.postCode=thisCell[2];
              placevo.placeType='area';
             
             placevo.parentPlaceId=1;
             
            
             placevo.trafficeGrade='1';
             placevo.remark=thisCell[3];
             
		         if(thisCell[4]==""){//新增的记录
                
                //padd.add('place',placevo) ;
                padd.add('ns1:WlPlaceVO',{id:999,parentPlaceId:1,placeName:thisCell[1],placeType:'area',postCode:thisCell[2],remark:thisCell[3],trafficeGrade:'1'});
//                padd.add('id',999);
//                padd.add('parentPlaceId',1);
//                padd.add('placeName',thisCell[1]);
//                padd.add('placeType','area');
//                padd.add('postCode',thisCell[2]);
//                padd.add('remark',thisCell[3]);
//                padd.add('trafficeGrade','1');
                SOAPClient.invoke(url, "createPlace", padd, false,  function GetEnu_callBack(ul, soapResponse){
                alert("add"+ul);
                });
             }else{//修改的记录
                var placevos=[placevo];
                padd.add('place',placevos) ;
                SOAPClient.invoke(url, "updatePlaces", padd, false,  function GetEnu_callBack(ul, soapResponse){
                alert(ul);
                });
             }
		       //gridWidget.updateRow();
          }    }
          
          
          function removeSelectedRows(){
                  
           gridWidget.removeSelectedRows();
          
          }   
           
         function init(){
         
           dojo.connect(gridWidget, "doStartEdit", function(inCell, inRowIndex){
        
                     var thisCell=gridWidget.model.data[inRowIndex];
		       		        if(thisCell[3]!=""){
                updata.splice(updata.length,thisCell);
            }
            });  
        
         
         
         
             //添加区域结点
                var url = "http://localhost:8080/logistics-ws/services/BasicManageService";
                var pl = new SOAPClientParameters();
                //pl.add('eType','区域') ;
                pl.add('type','area') ;
                SOAPClient.invoke(url, "getPlacevoByPlaceType", pl, false,  function GetEnu_callBack(ul, soapResponse){
                    ul=ul.out;
                     var pInfo = {
                        					parent: null,		
                        					attribute: "children"	
                        				};
                    for(var i = 0; i < ul.length; i++){		
                                 popStore.newItem({name: ul[i].placeName,type:ul[i].placeType ,eId:ul[i].id}, pInfo);
                            }
                        });
                       
                      
            //添加省份结点
            var chitem;
            var chdata =new Array();
            var _tree=dijit.byId("tree");
            var childrenArray1=_tree.getChildren();
            
            for (var i=0; i<childrenArray1.length; i++){//begin	
                var p2 = new SOAPClientParameters();
                
                var chNode =childrenArray1[i];
                chitem=chNode.item;
                var p2Info = {	parent: chitem,		
			                         	attribute: "children"	
			                       };
			    
                p2.add('parentPlaceId',chitem.eId) ;
                SOAPClient.invoke(url, "getPlacevoByParentPlaceId", p2 ,false,  function GetEnu_callBack(ul1, soapResponse){  
                    ul1=ul1.out;
                    for(var ii = 0; ii < ul1.length; ii++){	
                    	popStore.newItem({name: ul1[ii].placeName,type:ul1[ii].placeType ,eId:ul1[ii].id}, p2Info);
                        }
                   });
                }//end
                
                
               
           
                 
                 
                 //添加城市、城区结点
             dojo.connect(dijit.byId("tree"), "_onExpandoClick", function(message){
                           // _expandNode
                       var node = message.node;
                       var ch2node=node.getChildren();
                       // alert("erwer==="+ch2node.length);
                       for (var i=0; i<ch2node.length; i++){	//BEGIN
                       //alert(ch2node[i].getChildren().length);
                       if(ch2node[i].getChildren().length==0){
                         var ch2item =ch2node[i].item;
                         if(ch2item["type"]!='cityarea'){
                         var p3 = new SOAPClientParameters();
                         var p3Info = {
                                        parent: ch2item,		
                                        attribute: "children"	
                                       };
                        p3.add('parentPlaceId',ch2item["eId"]) ;
                        SOAPClient.invoke(url, "getPlacevoByParentPlaceId", p3 ,false,  function GetEnu_callBack(ul2, soapResponse){  
                            ul2=ul2.out;
                            for(var j = 0; j < ul2.length; j++){		
                                popStore.newItem( {name: ul2[j].placeName,type:ul2[j].placeType ,eId:ul2[j].id,code:ul2[j].postCode}, p3Info);
                         }});
                         }}
                      
                      }//END
             	 
            });
            
            
           
         
             
          
         //初始化列表----begin
         //初始化列表----end
            
            
            
           //查询列表----begin
             dojo.connect(_tree, "onClick", function(item,node){
                    placedata = new Array();
                    var identity = _tree.store.getIdentity(item);
                   // var eType=new String(item["type"]);
                   //var eType=item["type"];
                    var url0 = "http://localhost:8080/logistics-ws/services/BasicManageService";
                    var p0 = new SOAPClientParameters();
                   // p0.add('type',eType+'___') ;
                   p0.add('parentPlaceId',item["eId"]) ;
                SOAPClient.invoke(url0, "getPlacevoByParentPlaceId", p0, false,  function GetEnu_callBack(ul, soapResponse){   
                    ul=ul.out;
                     for(var i = 0; i < ul.length; i++){		
                      var items = new Array();
                        items[0] = false;
                        items[1] = ul[i].placeName;
                        items[2] = ul[i].postCode;
                        items[3] = ul[i].remark;
                        items[4] = ul[i].id;
                        //items[3] = ul[i].remark;
                        //items[4] = ul[i].;
                        placedata[i]=items;
                    }                
                });       
              model.setData(placedata);
                                     });  
            
            	model.setData(placedata);
            
            
            
            
           //查询列表----end
           dojo.connect(gridWidget.model, "onSelected", function(e){
                    alert("c3="+e);
                   // alert("3=="+e.cell.index);
            });  
          
        

            
           }//END INIT
            
           dojo.addOnLoad(init);
           

          
           
           
           
           
           
             
</script>
</head>
<body class="tundra">
       
	
	 <div dojoType="dijit.layout.SplitContainer"
                orientation="horizontal"
                sizerWidth="7"
                activeSizing="true"
               class ="split1" id="split1"
	             	style="border: 1px solid #bfbfbf;width: 1200px; height: 900px; " >
		
                <div dojoType="dijit.layout.ContentPane" id="treePane"  sizeMin="20" sizeShare="20"  onDownloadEnd="end" onLoad="myonDownloadEnd" >
                     <script>
                      var myonDownloadEnd=function(e){
                               document.split1.style.width=screen.availWidth; 
document.split1.style.height=screen.availHeight;
                      alert(document.split1.style.width);
                                                      };
              var end=function(e){
               document.split1.style.width=screen.availWidth; 
document.split1.style.height=screen.availHeight;
                      alert(document.split1.style.width);
      };
            
            
            </script>
                         <div id="tree"  class="container" dojoType="dijit.Tree"  store="popStore" labelAttr="name"  childrenAttr="children"  ></div> 
                </div>
                
                <div dojoType="dijit.layout.ContentPane" sizeMin="50" sizeShare="50"  >

   <div id="mainTabContainer" dojoType="dijit.layout.TabContainer"  style="width: 100%; height: 100%;"  >
        
      <!--div id="area" dojoType="dijit.layout.ContentPane" title="区域" selected="true" >
           <div id="areagrid" dojoType="dojox.Grid" jsId="areagridWidget"></div>
      </div>
      
      <div id="province" dojoType="dijit.layout.ContentPane" title="省"  >
           <div id="provincegrid" dojoType="dojox.Grid" jsId="provincegridWidget"></div>
      </div>
      
      <div id="city" dojoType="dijit.layout.ContentPane" title="城市"  >
           <div id="citygrid" dojoType="dojox.Grid" jsId="citygridWidget"></div>
      </div>
      
      <div id="cityarea" dojoType="dijit.layout.ContentPane" title="城区"  >
           <div id="cityareagrid" dojoType="dojox.Grid" jsId="cityareagridWidget"></div>
      </div-->
      
      <div id="LittleRed" dojoType="dijit.layout.ContentPane" title="地点"  style="width: 100%; height:200px;"  >

        <div id="grid" dojoType="dojox.Grid" defaultHeight="60" 	jsId="gridWidget"	model="model" structure="Layout" singleClickEdit="true" style="width: 100%; height: 95%;"  ></div>
        <div id="rowCount"></div>
        <div align="center">
         <button dojoType="dijit.form.Button" onclick="addRow()"> 新 增 </button>&nbsp;&nbsp;&nbsp;
         <button dojoType="dijit.form.Button" onclick="call_funUpd()">保 存</button>&nbsp;&nbsp;&nbsp;
         <button dojoType="dijit.form.Button" onclick="removeSelectedRows()">删 除</button>  
         </div>   
      </div>
      
      <div id="HanselGretel" dojoType="dijit.layout.ContentPane"
           title="路线" closable="true" >
           
      </div>
      
</div>

                       
                </div>
        </div>
</body></html>
